<style scoped lang="less">
</style>
<template>
	<div>
		<Row>
			<Col span="24">
				<Card style="margin-bottom: 10px">
					<Form inline>
						<FormItem style="margin-bottom: 0">
							<Select v-model="searchConf.type" clearable placeholder="请选择类型" style="width:100px">
								<Option v-for="item in typeList" :value="item.value">{{item.name}}</Option>
							</Select>
						</FormItem>
						<FormItem style="margin-bottom: 0">
							<Button type="primary" @click="search">{{ $t('find_button') }}/{{ $t('refresh_button') }}</Button>
						</FormItem>
					</Form>
				</Card>
			</Col>
		</Row>
		<Row>
			<Col span="24">
				<Card>
					<div>
						<Table :columns="columnsList" :data="tableData" border disabled-hover></Table>
					</div>
					<div class="margin-top-15" style="text-align: center">
						<Page :total="tableShow.listCount" :current="tableShow.currentPage"
						      :page-size="tableShow.pageSize" @on-change="changePage"
						      @on-page-size-change="changeSize" show-elevator show-sizer show-total></Page>
					</div>
				</Card>
			</Col>
		</Row>
	</div>
</template>
<script>
  //0待提现 5已提现 10关闭
  const TYPE_INCOME = 0;//收入
  const TYPE_EXPENDITURE = 1;//支出
  //收入或支出类型：0 分销 1 佣金 10其它 15退款  20购买产品 21购买会员 25其它
  const INCOME_TYPE_DISTRIBUTION = 0;//分销
  const INCOME_TYPE_REWORD = 1;//推广佣金
  const INCOME_TYPE_OTHER = 10;//其它收入
  const INCOME_TYPE_REFUND = 15;//退款

  const COST_TYPE_GOODS = 20;//购买产品
  const COST_TYPE_VIP = 21;//购买会员
  const COST_TYPE_WITHDRAWALS = 24;//提现
  const COST_TYPE_OTHER = 25;//其它
  import {getList} from '@/api/bill'

  let _this = null;

  export default {
    name: 'complain-list',
    data() {
      return {
        typeList: [{name: '收入', value: TYPE_INCOME}, {name: '支出', value: TYPE_EXPENDITURE}],
        show: false,
        loading: false,
        id: -1,
        itemData: null,
        columnsList: [
          {
            title: '序号',
            type: 'index',
            width: 65,
            align: 'center'
          },
          {
            title: '金额',
            align: 'center',
            render: (h, params) => {
              return h('span', params.row.money / 100)
            },
            width: 130
          },
          {
            title: '类型',
            align: 'center',
            render: (h, params) => {
              return h('span', params.row.type===TYPE_INCOME?"收入":"支出")
            },
            width: 120
          },
          {
            title: '创建日期',
            align: 'center',
            key: 'create_time',
            width: 180
          },
          {
            title: '来源',
            align: 'center',
            render: (h, params) => {
              return h('span', _this.getTypeStr(params.row.type))
            },
            width: 130
          },
          {
            title: '描述',
            align: 'center',
            key:'desc'
          }
        ],
        tableData: [],
        tableShow: {
          currentPage: 1,
          pageSize: 10,
          listCount: 0
        },
        searchConf: {
          type: null
        },
      }
    },
    created() {
      _this = this;
      this.getList()

    },
    methods: {
      getTypeStr(type) {
        let str = '';
        switch (type) {
          case INCOME_TYPE_DISTRIBUTION:
            str = '分销';
            break;
          case INCOME_TYPE_REWORD:
            str = '推广佣金';
            break;
          case INCOME_TYPE_OTHER:
            str = '其它';
            break;
          case INCOME_TYPE_REFUND:
            str = '退款';
            break;
          case COST_TYPE_GOODS:
            str = '购买产品';
            break;
          case COST_TYPE_VIP:
            str = '购买会员';
            break;
          case COST_TYPE_WITHDRAWALS:
            str = '提现';
            break;
          case COST_TYPE_OTHER:
            str = '其它';
            break;
        }
        return str;
      },
      changePage(page) {
        this.tableShow.currentPage = page;
        this.getList()
      },
      changeSize(size) {
        this.tableShow.pageSize = size;
        this.getList()
      },
      search() {
        this.tableShow.currentPage = 1;
        this.getList()
      },
      getList() {
        let vm = this;
        let params = {
          page: vm.tableShow.currentPage,
          size: vm.tableShow.pageSize,
          type: vm.searchConf.type
        };
        getList(params).then(response => {
          if (response.data.data.list != null) {
            vm.tableData = response.data.data.list
          } else {
            vm.tableData = [];
          }
          vm.tableShow.listCount = response.data.data.count
        })
      }
    }
  }
</script>
